import { getAntd, getEcCom, getLabel } from '../../../util/convert';
import { trim } from '../../../util/public/common';
import { observer, inject } from "mobx-react/index";
import { requestImport } from '../../../util/formUtil';

@inject('globalStore')
@observer
export default class Main extends React.Component {
	constructor(props) {
		super(props);
	}


render(){
	const { Modal, Button } = getAntd();
	const { WeaBrowser } = getEcCom();
	const { globalStore, menuName, workflowid = -1, formid, isbill, userId, loading = false } = this.props;
	const { JSComplete } = globalStore;
	const bottomBtn = [
		<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@16pejj@confirm`} type="primary" loading={loading} size="large" onClick={this.doSureEvent}>{getLabel(83446, '确定')}</Button>,
		<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@t3gzn1@cancel`} size="large" loading={loading} onClick={this.doCancelEvent}>{getLabel(31129, '取消')}</Button>
	];

	const conditionDataParams = { importWfBrow: '1', workflowid: workflowid };
	const dataParams = { importWfBrow: '1', formid, isbill };
	return (
		<WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@z92i9l`} type={"16"}
			title={getLabel(24270, "导入流程")}
			isSingle={true}
			icon={"icon-coms-workflow"}
			iconColor={"#fff"}
			iconBgcolor={"#0079DE"}
			viewAttr={2}
			customized={true}
			hasAdvanceSerach={true}
			hasRadio={true}
			ref={ImportWfBrowser=> window.ImportWfBrowser = ImportWfBrowser}
			dataParams={dataParams}
			conditionDataParams={conditionDataParams}
			buttons={bottomBtn}
		>
		</WeaBrowser>
	)
}

doSureEvent = () => {
	const { Modal } = getAntd();
	const warning = Modal.warning;
	const browser = window.ImportWfBrowser;
	const newRequestid = browser.get() ? browser.get().id : '';
	if (trim(newRequestid).length > 0) {
		browser.closeModal && browser.closeModal();
		requestImport(newRequestid);
	} else {
		warning({
			content: getLabel(20149, "请至少选择一条记录。"),
			okText: getLabel(83446, '确定'),
			showClose: false,
			onOk() { }
		});
	}
}

doCancelEvent = () => {
	const browser = window.ImportWfBrowser;
	browser.closeModal();
}
}

const openImportWfWindow = (url) => {
	var redirectUrl = url;
	var width = 780;
	var height = 590;
	var left = (screen.availWidth - 780) / 2;
	var top = (screen.availHeight - 590) / 2;
	var  szFeatures= "top=" + top + ",";
	szFeatures += "left=" + left + ",";
	szFeatures += "width=" + width + ",";
	szFeatures += "height=" + height + ",";
	szFeatures += "directories=no,";
	szFeatures += "status=yes,toolbar=no,location=no,";
	szFeatures += "menubar=no,";
	szFeatures += "scrollbars=yes,";
	szFeatures += "resizable=yes"; //channelmode
	window.open(redirectUrl, "", szFeatures);
}

window.openImportWfWindow = openImportWfWindow;
